const { addOrders, getOrders, getOrdersById, disposeOrdersToCancel, getToCancelOrders,submitOrdersToCancel,changeOrderById } = require('../dao/ordersDao');
module.exports.addOrders = async function (params) {
    const data = await addOrders(params);
    if (data._id) {
        return {
            message: '新增成功',
            status: 1
        }
    }
    else {
        return {
            message: '新增失败',
            status: 0
        }
    }
}
module.exports.getToCancelOrders = async function (params) {
    const data = await getToCancelOrders(params)
    if (data.length > 0) {
        return {
            message: "获取成功",
            status: 1,
            data
        }
    } else {
        return {
            message: "获取失败",
            status: 0,
        }
    }
}

module.exports.getOrders = async function (params) {
    return await getOrders(params);
}
module.exports.getOrdersById = async function (params) {
    return await getOrdersById(params);
}

module.exports.disposeOrdersToCancel = async function (params) {
    const data = await disposeOrdersToCancel(params);
    if (data.nModified > 0) {
        return {
            message: '修改状态成功',
            status: 1
        }
    }
    else {
        return {
            message: '未改动状态',
            status: 0
        }
    }
}


module.exports.submitOrdersToCancel = async function (params) {
    const data = await submitOrdersToCancel(params);
    console.log(data);
    if (data.nModified > 0) {
        return {
            message: '提交成功',
            status: 1
        }
    }
    else {
        return {
            message: '提交失败',
            status: 0
        }
    }
}


module.exports.changeOrderById = async function (params) {
    const data = await changeOrderById(params);
    console.log(data);
    if (data.nModified > 0) {
        return {
            message: '修改成功',
            status: 1
        }
    }
    else {
        return {
            message: '提交失败',
            status: 0
        }
    }
}